//
//  ContactCell.m
//  EWork
//
//  Created by administrator on 14-11-29.
//  Copyright (c) 2014年 gaobo. All rights reserved.
//

#import "ContactCell.h"
#define kHeadImageXY 5
#define kHeadImageWH 50
#define kMargin 10
#define kNameLabelW 60
#define kNameLabelH 20
#define kDetailLabelW 260


@implementation ContactCell

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.headImage=[[UIImageView alloc]init];
        [self.contentView addSubview:self.headImage];
        self.nameLabel=[[UILabel alloc]init];
        [self.contentView addSubview:self.nameLabel];
        self.detailLabel=[[UILabel alloc]init];
        [self.contentView addSubview:self.detailLabel];
    }
    return self;
}
- (void)layoutSubviews{
    CGFloat headImageX = kHeadImageXY;
    CGFloat headImageY = kHeadImageXY;
    CGFloat headImageWH = kHeadImageWH;
    self.headImage.frame = CGRectMake(headImageX, headImageY, headImageWH, headImageWH);
    
    CGFloat nameLabelX = headImageX + headImageWH + kMargin;
    CGFloat nameLabelY = headImageY;
    CGFloat nameLabelW = kNameLabelW;
    CGFloat nameLabelH = kNameLabelH;
    self.nameLabel.frame = CGRectMake(nameLabelX, nameLabelY, nameLabelW, nameLabelH);
    
    CGFloat detailLabelX = nameLabelX;
    CGFloat detailLabelY = nameLabelY + kNameLabelH + kMargin;
    CGFloat detailLabelW = kDetailLabelW;
    CGFloat detailLabelH = nameLabelH;
    self.detailLabel.frame = CGRectMake(detailLabelX, detailLabelY, detailLabelW, detailLabelH);
}


- (void)setSelected:(BOOL)selected animated:(BOOL)animated{
    [super setSelected:selected animated:animated];
}

-(void)setContact:(Contact *)contact{
    _contact=contact;
    self.headImage.image = [UIImage imageNamed:_contact.headImage];
    self.nameLabel.text = _contact.name;
    self.detailLabel.text = [NSString stringWithFormat:@"%@-%@",_contact.department,_contact.job];
}
@end
